<?php
/*type=Service*/

	class Modules_Core_Model_Login
	{
		public $result=array("error"=>"","result"=>0);
		public function Modules_Core_Model_Login($args=null)
		{
			if($args==null)
				return;
			try{
				$user=Modules_Common_DB_Users::ByEmail($args['email']);
				if($user==null && count($user)==1)
					throw new Exception();
				
				$user=reset($user);	
				if($user->validatePassword($args['password']))
					$this->result["result"]=1;
				else
					throw new Exception();
				$_SESSION['id']=$user->id;
				$_SESSION['user_object']=serialize(new Modules_Common_DB_Users($user->id));
				
			}
			catch(Exception $e)
			{
				$this->result["result"]=0;
				$this->result["error"]="Error making authentication";
			}
		}
	}